package com.ld.common.webnotice.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

import com.ld.common.webnotice.socket.SocketIOServerUtil;

import lombok.extern.slf4j.Slf4j;

@ConditionalOnProperty(prefix = "shieldsb.socketio", name = "enable", havingValue = "true", matchIfMissing = true)
@Configuration
@Slf4j
public class SocketioLisener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.warn("contextInitialized==================start");
        // 启动Socketio服务
//        SocketIO socketio = new SocketIO();
//        socketio.start();
        SocketIOServerUtil.SOCKET_IO_SERVICE.start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 关闭Socketio服务
//        SocketIO socketio = new SocketIO();
//        socketio.stop();
        SocketIOServerUtil.SOCKET_IO_SERVICE.stop();
    }

}
